/*package com.utils.spring;

import java.io.InputStream;
import java.util.Arrays;
import java.util.Date;

import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.exceptions.ClientException;
import com.kyhd.lib.exception.NotLoginException;
import com.kyhd.toutiao.controller.model.ImageRequest;
import com.kyhd.toutiao.controller.model.LoginResponse;
import com.kyhd.toutiao.controller.model.QuickLoginRequest;
import com.kyhd.toutiao.controller.model.ReqCtx;
import com.kyhd.toutiao.controller.model.StatLog;
import com.kyhd.toutiao.controller.model.UserInfoResponse;
import com.kyhd.toutiao.controller.model.UserResponse;
import com.kyhd.toutiao.dao.model.User;
import com.kyhd.toutiao.dao.model.UserBindCash;
import com.kyhd.toutiao.service.MentoringService;
import com.kyhd.toutiao.service.OSSService;
import com.kyhd.toutiao.service.RedisService;
import com.kyhd.toutiao.service.StatLogService;
import com.kyhd.toutiao.service.TaskService;
import com.kyhd.toutiao.service.UserBindCashService;
import com.kyhd.toutiao.service.UserLiveService;
import com.kyhd.toutiao.service.UserService;
import com.kyhd.toutiao.util.DateUtil;
import com.kyhd.toutiao.util.EncrypUtil;
import com.kyhd.toutiao.util.InitConst;
import com.kyhd.toutiao.util.LogUtil;
import com.kyhd.toutiao.util.ReqCtxUtil;
import com.kyhd.toutiao.util.RequestContextLog;
import com.kyhd.toutiao.util.SendMessage;
import com.kyhd.toutiao.util.TaskConst;
import com.kyhd.toutiao.util.ThreadLocalUtil;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;

@Api("用户管理接口")
@RestController
@Slf4j
@RequestMapping(value = "/tt/api/user", produces = { "application/json" })
public class UserController {

	@Autowired
	UserLiveService userLiveService;
	
	@Autowired
	UserService userService;

	@Autowired
	UserBindCashService userBindCashService;
	
	@Autowired
	RedisService redisService;
	
	@Autowired
	OSSService ossService;
	
	@Autowired
	StatLogService statLogService;
	
	@Autowired
	MentoringService mentoringService;
	
	@Autowired
	TaskService taskService;

	@ApiOperation(value = "返回服务器时间,且更新打开app时间", notes = "") 
	@RequestMapping(method = { RequestMethod.GET }, path = "/time")
	public @ResponseBody ResponseEntity<String> getTimeAndUpdateOpenTime() {
		RequestContextLog ctx = ThreadLocalUtil.requestCtxTL.get();
		String uuid = ctx.getUuid();
		log.info("User getTimeAndUpdateOpenTime request uuid:{}",uuid);
		HttpHeaders headers = new HttpHeaders();
		headers.put(HttpHeaders.CONTENT_TYPE, Arrays.asList("application/json;charset=UTF-8"));
		
		String nowTimes = (String.valueOf(System.currentTimeMillis())).substring(0, 10);
		
		if(uuid!=null&&!"".equals(uuid)) {
			Object obj = this.redisService.getValue(uuid);
			if(obj!=null&&!"".equals(obj.toString())) {
				try {
					//更新opentime 
					this.userLiveService.updateOpenTime(uuid);
				} catch (Exception e) {
					log.info("User getTimeAndUpdateOpenTime uuid:{},token:{},e:{}",uuid,obj.toString(),e.getMessage());
				}
			}
		}
		
		JSONObject ret = new JSONObject();
		ret.put("timestamp", nowTimes);
		ret.put("status", InitConst.API_STATUS_SUCCESS);
		ret.put("message", "success");
		log.info("User getTimeAndUpdateOpenTime response:{}",ret.toString());
		return new ResponseEntity<String>(ret.toJSONString(), headers, HttpStatus.OK);	
	}
	
	
	@ApiOperation(value = "获取验证码", notes = "") 
	@RequestMapping(method = { RequestMethod.GET }, path = "/getcode")
	public @ResponseBody UserResponse getVerificationCode(
			@ApiParam(value = "手机号") @RequestParam(name = "phone", required = true) String phone,
			@ApiParam(value = "时间戳") @RequestParam(name = "times", required = true) long times
			) {
		log.info("user getVerificationCode request phone:{},times:{}", phone,times);
		UserResponse response = new UserResponse();
		String timestr = (times+"").substring(0, 10);
		
		long nowTimes = DateUtil.getMills(new Date(), null);
		if (((nowTimes/1000) - Long.valueOf(timestr)) > InitConst.URL_TIMEOUT
				||(Long.valueOf(timestr) - (nowTimes/1000)) > InitConst.URL_TIMEOUT) {
			response.setStatus(InitConst.API_STATUS_FAILED);
			response.setMessage("获取失败，请您同步联网时间");
			log.info("user getVerificationCode response:{}", response);
			return response;
		}
        
		String ePhone = "0";
		try {
			ePhone = EncrypUtil.desEncrypt(phone, timestr+InitConst.YZM_KEY);
		} catch (Exception e1) {
			response.setUuid(ePhone);
			response.setStatus(InitConst.API_STATUS_FAILED);
			response.setMessage("电话号错误");
			log.info("user getVerificationCode response:{}", response);
			return response;
		}
		if("0".equals(ePhone)) {
			response.setUuid(ePhone);
			response.setStatus(InitConst.API_STATUS_FAILED);
			response.setMessage("电话号错误");
			log.info("user getVerificationCode response:{}", response);
			return response;
		}
		
		log.info("user getVerificationCode request desEncryptPhone:{},times:{}", ePhone,times);

		Object obj = this.redisService.getValue("yzmcode:"+ePhone);
		if(obj!=null) {
			response.setUuid(ePhone);
			response.setStatus(InitConst.API_STATUS_FAILED);
			response.setMessage("半分钟内只能获得一次验证码，请您稍后再发送");
			log.info("user getVerificationCode response:{}", response);
			return response;
		}
		
		String code = SendMessage.createCode();
		String status = null;
		try {
			status = SendMessage.send(ePhone, code);
		} catch (ClientException e) {
			response.setUuid(ePhone);
			response.setStatus(InitConst.API_STATUS_FAILED);
			response.setMessage("验证码发送异常,请您重新发送");
			log.info("user getVerificationCode response:{}", response);
			return response;
		}
		if (!"OK".equals(status)) {
			response.setUuid(ePhone);
			response.setStatus(InitConst.API_STATUS_FAILED);
			response.setMessage("验证码未发送成功,请您稍候重新发送");
			log.info("user getVerificationCode response:{}", response);
			return response;
		}
		this.redisService.setKeyByMinutes(ePhone, code, InitConst.SMS_TIMEOUT);// 设置超时时间为5分钟
		this.redisService.setKeyBySecond("yzmcode:"+ePhone, "yzmcode", 30); //30秒内不得再次发送
		
		response.setUuid(ePhone);
		response.setStatus(InitConst.API_STATUS_SUCCESS);
		response.setMessage("验证码发送成功,请您查收短信");
		log.info("user getVerificationCode response:{}", response);
		return response;
	}

	@ApiOperation(value = "用户登陆", notes = "")
	@RequestMapping(method = { RequestMethod.POST }, path = "/login")
	public @ResponseBody LoginResponse login(
			@ApiParam(value = "手机号") @RequestParam(name = "phone", required = true) String phone,
			@ApiParam(value = "验证码") @RequestParam(name = "code", required = true) String code,
			@ApiParam(value = "设备ID") @RequestParam(name = "deviceID", required = true) String deviceID,
			@ApiParam(value = "渠道号") @RequestParam(name = "channelCode", required = true) String channelCode,
			@ApiParam(value = "设备型号") @RequestParam(name = "mobileModel", required = true) String mobileModel,
			@ApiParam(value = "时间戳") @RequestParam(name = "times", required = true) long times) {
		log.info("user login request encrypt phone:{},code:{},deviceID:{},channelCode:{},mobileModel:{}", phone, code, deviceID,
				channelCode, mobileModel);

		LoginResponse response = new LoginResponse();
		String timestr = (times+"").substring(0, 10);

		long nowTimes = DateUtil.getMills(new Date(), null);
		if (((nowTimes/1000) - Long.valueOf(timestr)) > InitConst.URL_TIMEOUT
				||(Long.valueOf(timestr) - (nowTimes/1000)) > InitConst.URL_TIMEOUT) {
			response.setStatus(InitConst.API_STATUS_FAILED);
			response.setMessage("Not login");
			log.info("user login response:{}", response);
			return response;
		}
		
		String ePhone = "";
		String eCode = "";
		String eDeviceID = "";
		String eChannelCode = "";
		String eMobileModel = "";
		String edata = "";
		
		try {
			ePhone = EncrypUtil.desEncrypt(phone, timestr+InitConst.YZM_KEY);
			eCode = EncrypUtil.desEncrypt(code, timestr+InitConst.YZM_KEY);
			eDeviceID = EncrypUtil.desEncrypt(deviceID, timestr+InitConst.YZM_KEY);
			eChannelCode = EncrypUtil.desEncrypt(channelCode, timestr+InitConst.YZM_KEY);
			eMobileModel = EncrypUtil.desEncrypt(mobileModel, timestr+InitConst.YZM_KEY);

		} catch (Exception e1) {
			response.setStatus(InitConst.API_STATUS_FAILED);
			response.setMessage("数据异常");
			log.info("user login response:{}", response);
			return response;
		}
		
		response = this.userService.login(ePhone, eCode, eDeviceID,
				eChannelCode, eMobileModel,edata);
		
		log.info("user login response:{}", response);
		return response;
	}

	@ApiOperation(value = "获取用户信息", notes = "")
	@RequestMapping(method = { RequestMethod.GET }, path = "/getuser")
	public @ResponseBody UserInfoResponse getUserInfo(
			@ApiParam(value = "用户ID") @RequestParam(name = "uuid", required = true) String uuid,
			@ApiParam(value = "时间戳") @RequestParam(name = "times", required = true) long times,
			@ApiParam(value = "签名") @RequestParam(name = "sign", required = true) String sign) throws Exception {
		log.info("user getUserInfo request uuid:{},times:{},sign:{}", uuid, times, sign);
		ReqCtx ctx = ReqCtxUtil.reqCtx.get();
		if (ctx == null) {
			throw new NotLoginException();
		}
		String ctxUuid = ctx.getUuid();
		String token = ctx.getToken();

		UserInfoResponse response = new UserInfoResponse();
		User user = this.userService.getByUUID(ctxUuid);
		if (user == null) {
			response.setUuid(ctxUuid);
			response.setStatus(InitConst.API_STATUS_FAILED);
			response.setMessage("没有找到此用户的信息");
			log.info("user getUserInfo response:{}", response);
			return response;
		}
		
		String imagePath = "";
		if(user.getImage()!=null&&!"".equals(user.getImage())) {
			imagePath = this.ossService.getUrl()+user.getImage();
		}
		
		String isBindWechat = InitConst.NO;
		String loginType = user.getType()+"";
		String wechatName = "";
		String wechatOpenid = user.getWechatOpenid();
		if(wechatOpenid!=null&&!"".equals(wechatOpenid)) {
			UserBindCash userBindCash = this.userBindCashService.getBindWechatByUUIDandOpenID(ctxUuid, wechatOpenid);
			if(userBindCash!=null) {
				isBindWechat = InitConst.YES;
				wechatName = userBindCash.getNickName();
			} 
		}
		
		JSONObject ret = new JSONObject();
		ret.put("phone", user.getPhone());
		ret.put("image", imagePath);
		ret.put("nickNmae", user.getNickName());

		StatLog _log = new StatLog();
		_log.setCtime(DateTime.now());
		_log.setAction(LogUtil.LogActions.获取用户信息.getVal());
		_log.setInfo(ret.toString());
		statLogService.writerLog(_log);
		
		log.info("user getUserInfo uuid:{},image:{},nickNmae:{},phone:{},sex:{},birthday:{},isBindWechat:{},wechatName:{},loginType:{}"
				, ctxUuid,imagePath,user.getNickName(),user.getPhone(),user.getSex(),user.getBirthday(),isBindWechat,wechatName,loginType);

		response.setUuid(ctxUuid);
		response.setImage(EncrypUtil.encryptByToken(imagePath, token));
		response.setNickName(EncrypUtil.encryptByToken(user.getNickName(), token));
		if(user.getPhone()!=null&&!"".equals(user.getPhone())) {
			response.setPhone(EncrypUtil.encryptByToken(user.getPhone().substring(0, 3) + "****" + user.getPhone().substring(7, 11), token));
		}else {
			response.setPhone(EncrypUtil.encryptByToken(user.getPhone(), token));
		}
		if(user.getSex()!=null&&user.getSex()!=0) {
			response.setSex(EncrypUtil.encryptByToken(user.getSex() + "", token));
		}else {
			response.setSex("");
		}
		if(user.getBirthday()!=null&&!"".equals(user.getBirthday())) {
			response.setBirthDay(EncrypUtil.encryptByToken(user.getBirthday(), token));
		}else {
			response.setBirthDay("");
		}
		response.setInvitateCode(EncrypUtil.encryptByToken(user.getInviteCode(), token));
		response.setBindWechat(EncrypUtil.encryptByToken(isBindWechat, token));
		response.setWechatName(EncrypUtil.encryptByToken(wechatName, token));
		response.setLoginType(EncrypUtil.encryptByToken(loginType, token));
		response.setStatus(InitConst.API_STATUS_SUCCESS);
		response.setMessage("获取信息成功");

		log.info("user getUserInfo response:{}", response);
		return response;
	}

	@ApiOperation(value = "修改用户头像", notes = "")
	@RequestMapping(method = { RequestMethod.POST }, path = "/updateimage")
	public @ResponseBody UserResponse updateImage(@RequestBody ImageRequest request) {
		log.info("user updateImage imageRequest request":{}", request);
		ReqCtx ctx = ReqCtxUtil.reqCtx.get();
		if (ctx == null) {
			throw new NotLoginException();
		}
		String ctxUuid = ctx.getUuid();
		String token = ctx.getToken();
		String image = request.getImage().trim();
		
		UserResponse response = new UserResponse();
		
		if(image==null||"".equals(image)) {
			response.setUuid(ctxUuid);
			response.setStatus(InitConst.API_STATUS_FAILED);
			response.setMessage("上传失败");
			log.info("user updateImage response:{}", response);
			return response;
		}
		try {
			//将base64的image转化为inputStream
			String fileName =this.ossService.createImgName(ctxUuid);
			InputStream is = EncrypUtil.base64ToInputStream(image);
			//上传到oss
			String imagePath = this.ossService.uploadCommon(is,fileName);
			log.info("user updateImage imagePath:{}", imagePath);
			this.userService.updateImage(ctxUuid, imagePath);
			//将url加密后返回
			imagePath =  this.ossService.getUrl()+imagePath;
			String eImagePath = EncrypUtil.encryptByToken(imagePath, token);
			response.setUuid(ctxUuid);
			response.setStatus(InitConst.API_STATUS_SUCCESS);
			response.setMessage(eImagePath);
			log.info("user updateImage response:{}", response);
			return response;
		} catch (Exception e) {
			e.printStackTrace();
		}
		response.setUuid(ctxUuid);
		response.setStatus(InitConst.API_STATUS_FAILED);
		response.setMessage("上传异常");
		log.error("user updateImage response:{}", response);
		return response;
	}

	@ApiOperation(value = "修改用户性别", notes = "")
	@RequestMapping(method = { RequestMethod.POST }, path = "/updatesex")
	public @ResponseBody UserResponse updateSex(
			@ApiParam(value = "用户ID") @RequestParam(name = "uuid", required = true) String uuid,
			@ApiParam(value = "时间戳") @RequestParam(name = "times", required = true) long times,
			@ApiParam(value = "签名") @RequestParam(name = "sign", required = true) String sign,
			@ApiParam(value = "性别 0无，1男，2女") @RequestParam(name = "data", required = true) String sex) {
		log.info("user updateSex request uuid:{},times:{},sign:{},data:{}", uuid, times, sign, sex);
		ReqCtx ctx = ReqCtxUtil.reqCtx.get();
		if (ctx == null) {
			throw new NotLoginException();
		}
		String ctxUuid = ctx.getUuid();
		String data = ctx.getData();

		UserResponse response = new UserResponse();
		try {
			
			User user = this.userService.getByUUID(ctxUuid);
			boolean a = true;
			if(user!=null&&user.getSex()!=null&&user.getSex()!=0) {
				a = false; 
			}
			
			this.userService.updateSex(ctxUuid, Short.valueOf(data));
			
			JSONObject ret = new JSONObject();
			ret.put("sex", data);
			
			StatLog _log = new StatLog();
			_log.setCtime(DateTime.now());
			_log.setAction(LogUtil.LogActions.更新性别.getVal());
			_log.setInfo(ret.toString());
			statLogService.writerLog(_log);
			
			if(user!=null&&a) {
				this.taskService.completeTaskByType(ctxUuid,TaskConst.TaskType.设置性别.getType());
			}
			
			response.setUuid(ctxUuid);
			response.setStatus(InitConst.API_STATUS_SUCCESS);
			if(a) {
				response.setMessage("获得500金币");
			}else {
				response.setMessage("修改成功");
			}
			log.info("user updateSex response:{}", response);
			return response;
		} catch (Exception e) {
			e.printStackTrace();
		}
		response.setUuid(ctxUuid);
		response.setStatus(InitConst.API_STATUS_FAILED);
		response.setMessage("修改失败,请您稍后重试~");
		log.info("user updateSex response:{}", response);
		return response;
	}

	@ApiOperation(value = "修改用户昵称", notes = "")
	@RequestMapping(method = { RequestMethod.POST }, path = "/updatenick")
	public @ResponseBody UserResponse updateNickName(
			@ApiParam(value = "用户ID") @RequestParam(name = "uuid", required = true) String uuid,
			@ApiParam(value = "时间戳") @RequestParam(name = "times", required = true) long times,
			@ApiParam(value = "签名") @RequestParam(name = "sign", required = true) String sign,
			@ApiParam(value = "昵称") @RequestParam(name = "data", required = true) String nickName) {
		log.info("user updateNickName request uuid:{},times:{},sign:{},data:{}", uuid, times, sign, nickName);
		ReqCtx ctx = ReqCtxUtil.reqCtx.get();
		if (ctx == null) {
			throw new NotLoginException();
		}
		String ctxUuid = ctx.getUuid();
		String data = ctx.getData().trim();

		UserResponse response = new UserResponse();
		try {
			if(data!=null&&!"".equals(data)&&data.length()<=20) {
				
				this.userService.updateNickName(ctxUuid, data);
				
				response.setUuid(ctxUuid);
				response.setStatus(InitConst.API_STATUS_SUCCESS);
				response.setMessage("修改成功");
				log.info("user updateNickName response:{}", response);
				return response;
			}
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		response.setUuid(ctxUuid);
		response.setStatus(InitConst.API_STATUS_FAILED);
		response.setMessage("修改失败,请您稍后重试~");
		log.info("user updateNickName response:{}", response);
		return response;
	}

	@ApiOperation(value = "修改用户生日", notes = "")
	@RequestMapping(method = { RequestMethod.POST }, path = "/updatebirthday")
	public @ResponseBody UserResponse updateBirthday(
			@ApiParam(value = "用户ID") @RequestParam(name = "uuid", required = true) String uuid,
			@ApiParam(value = "时间戳") @RequestParam(name = "times", required = true) long times,
			@ApiParam(value = "签名") @RequestParam(name = "sign", required = true) String sign,
			@ApiParam(value = "生日") @RequestParam(name = "data", required = true) String birthday) {
		log.info("user updateBirthday request uuid:{},times:{},sign:{},data:{}", uuid, times, sign, birthday);
		ReqCtx ctx = ReqCtxUtil.reqCtx.get();
		if (ctx == null) {
			throw new NotLoginException();
		}
		String ctxUuid = ctx.getUuid();
		String data = ctx.getData();

		UserResponse response = new UserResponse();
		try {
			
			User user = this.userService.getByUUID(ctxUuid);
			boolean a = true;
			if(user!=null&&user.getBirthday()!=null&&!"".equals(user.getBirthday())) {
				a = false; 
			}
			
			this.userService.updateBirthday(ctxUuid, data);
			
			JSONObject ret = new JSONObject();
			ret.put("birthday", data);
			
			StatLog _log = new StatLog();
			_log.setCtime(DateTime.now());
			_log.setAction(LogUtil.LogActions.更新生日.getVal());
			_log.setInfo(ret.toString());
			statLogService.writerLog(_log);
			
			if(user!=null&&a) {
				this.taskService.completeTaskByType(ctxUuid,TaskConst.TaskType.设置生日.getType());
			}
			
			response.setUuid(ctxUuid);
			response.setStatus(InitConst.API_STATUS_SUCCESS);
			if(a) {
				response.setMessage("获得300金币");
			}else {
				response.setMessage("修改成功");
			}
			log.info("user updateBirthday response:{}", response);
			return response;
		} catch (Exception e) {
			e.printStackTrace();
		}
		response.setUuid(ctxUuid);
		response.setStatus(InitConst.API_STATUS_FAILED);
		response.setMessage("修改失败,请您稍后重试~");
		log.info("user updateBirthday response:{}", response);
		return response;
	}

	@ApiOperation(value = "绑定手机号", notes = "")
	@RequestMapping(method = { RequestMethod.POST }, path = "/bindphone")
	public @ResponseBody UserResponse bindPhone(
			@ApiParam(value = "用户ID") @RequestParam(name = "uuid", required = true) String uuid,
			@ApiParam(value = "时间戳") @RequestParam(name = "times", required = true) long times,
			@ApiParam(value = "签名") @RequestParam(name = "sign", required = true) String sign,
			@ApiParam(value = "手机号,验证码。用“,”号连接") @RequestParam(name = "data", required = true) String phoneAndCode) {
		log.info("user bindPhone request uuid:{},times:{},sign:{},data:{}", uuid, times, sign, phoneAndCode);
		ReqCtx ctx = ReqCtxUtil.reqCtx.get();
		if (ctx == null) {
			throw new NotLoginException();
		}
		
		String ctxUuid = ctx.getUuid();
		String data = ctx.getData();
		UserResponse response = new UserResponse();
		String d[] = data.split(",");
		String phone = "";
		String code = "";
		try {
			phone = d[0].trim();
			code = d[1].trim();
		} catch (Exception e) {
			
		}
		if("".equals(phone)) {
			response.setStatus(InitConst.API_STATUS_FAILED);
			response.setMessage("请您输入手机号");
			return response;
		}
		if("".equals(code)) {
			response.setStatus(InitConst.API_STATUS_FAILED);
			response.setMessage("请您输入验证码");
			return response;
		}

		Object objCode = this.redisService.getValue(phone);
		if (objCode == null || "".equals(objCode.toString())) {
			response.setStatus(InitConst.API_STATUS_FAILED);
			response.setMessage("验证码已失效，请您重新获取验证码");
			return response;
		} else {
			if (code.equals(objCode.toString())) {
				User user = this.userService.getByPhone(phone);
				if(user!=null&&user.getUuid()!=ctxUuid) {
					response.setStatus(InitConst.API_STATUS_FAILED);
					response.setMessage("该手机号已绑定其他账号，不能进行绑定");
					log.info("user bindPhone response:{}", response);
					return response;
				}
				try {
					log.info("user bindPhone ctxUuid:{}, phone:{}", ctxUuid, phone);
					User user1 = this.userService.getByUUID(ctxUuid);
					if(user1!=null) {
						if(user1.getPhone()!=null&&!"".equals(user1.getPhone())) {
							JSONObject ret = new JSONObject();
							ret.put("phone", phone);
							
							StatLog _log = new StatLog();
							_log.setCtime(DateTime.now());
							_log.setAction(LogUtil.LogActions.重新绑定手机号.getVal());
							_log.setInfo(ret.toString());
							statLogService.writerLog(_log);
						}else {
							JSONObject ret = new JSONObject();
							ret.put("phone", phone);
							
							StatLog _log = new StatLog();
							_log.setCtime(DateTime.now());
							_log.setAction(LogUtil.LogActions.绑定手机号.getVal());
							_log.setInfo(ret.toString());
							statLogService.writerLog(_log);
						}
					}
					this.userService.bindPhone(ctxUuid, phone);
				} catch (Exception e) {
					e.printStackTrace();
					response.setUuid(ctxUuid);
					response.setStatus(InitConst.API_STATUS_FAILED);
					response.setMessage("修改失败,请您稍后重试~");
					log.info("user bindPhone response:{}", response);
					return response;
				}
				
				Object mid = this.redisService.getValue(InitConst.PREA_PREFIX+phone);
				if(mid!=null) {
					this.mentoringService.preMentoring(mid.toString(), ctxUuid);
					//删除预收徒弟redis 
					this.redisService.deleteKey(InitConst.PREA_PREFIX+phone);
				}
				
				this.redisService.deleteKey(phone);
			}else {
				response.setStatus(InitConst.API_STATUS_FAILED);
				response.setMessage("验证码不正确，请您重新输入");
				log.info("user bindPhone response:{}", response);
				return response;
			}
		}

		response.setUuid(ctxUuid);
		response.setStatus(InitConst.API_STATUS_SUCCESS);
		response.setMessage("绑定成功");
		log.info("user bindPhone response:{}", response);
		return response;
	}

	@ApiOperation(value = "用户退出登陆", notes = "")
	@RequestMapping(method = { RequestMethod.DELETE }, path = "/quit")
	public @ResponseBody UserResponse quitLogin(
			@ApiParam(value = "用户ID") @RequestParam(name = "uuid", required = true) String uuid,
			@ApiParam(value = "时间戳") @RequestParam(name = "times", required = true) long times,
			@ApiParam(value = "签名") @RequestParam(name = "sign", required = true) String sign) {
		log.info("user quit request uuid:{},times:{},sign:{}", uuid, times, sign);
		ReqCtx ctx = ReqCtxUtil.reqCtx.get();
		if (ctx == null) {
			throw new NotLoginException();
		}
		String ctxUuid = ctx.getUuid();

		UserResponse response = new UserResponse();
		this.redisService.deleteKey(ctxUuid);

		response.setUuid(ctxUuid);
		response.setStatus(InitConst.API_STATUS_SUCCESS);
		response.setMessage("退出登陆成功");
		log.info("user quit response:{}", response);
		return response;
	}

	@ApiOperation(value = "微信快捷登陆", notes = "")
	@RequestMapping(method = { RequestMethod.POST }, path = "/welogin")
	public @ResponseBody LoginResponse weChatLogin(@RequestBody QuickLoginRequest request) {
		log.info("user weChatLogin request:{},", request);
		LoginResponse response = new LoginResponse();
		if(request.getTimes()<=0) {
			response.setStatus(InitConst.API_STATUS_FAILED);
			response.setMessage("登陆失败，请您同步联网时间");
			log.info("user weChatLogin response:{}", response);
			return response;
		}
		String timestr = (request.getTimes()+"").substring(0, 10);
		long nowTimes = DateUtil.getMills(new Date(), null);
		if (((nowTimes/1000) - Long.valueOf(timestr)) > InitConst.URL_TIMEOUT
				||(Long.valueOf(timestr) - (nowTimes/1000)) > InitConst.URL_TIMEOUT) {
			response.setStatus(InitConst.API_STATUS_FAILED);
			response.setMessage("登陆失败，请您同步联网时间");
			log.info("user weChatLogin response:{}", response);
			return response;
		}
		
		String edata = request.getData();
		if(edata==null||"".equals(edata)) {
			response.setStatus(InitConst.API_STATUS_FAILED);
			response.setMessage("数据异常");
			log.info("user weChatLogin response:{}", response);
			return response;
		}
		
		String data = null;
		try {
			data = EncrypUtil.desEncrypt(edata, request.getTimes()+InitConst.THIRD_KEY);
		} catch (Exception e) {
			response.setStatus(InitConst.API_STATUS_FAILED);
			response.setMessage("数据异常");
			log.info("user weChatLogin response:{}", response);
			return response;
		}
		if(data!=null&&!"".equals(data)) {
			response = this.userService.weLogin(data);
		}else {
			response.setStatus(InitConst.API_STATUS_FAILED);
			response.setMessage("服务器繁忙，请您稍候重试~");
		}
		log.info("user weChatLogin response:{},", response);
		return response;
	}
	
	@ApiOperation(value = "绑定微信", notes = "")
	@RequestMapping(method = { RequestMethod.POST }, path = "/bindwechat")
	public @ResponseBody UserResponse bindWechat(@RequestBody QuickLoginRequest request) {
		log.info("user bindWechat request:{},", request);
		ReqCtx ctx = ReqCtxUtil.reqCtx.get();
		if (ctx == null) {
			throw new NotLoginException();
		}
		String ctxUuid = ctx.getUuid();
		String token = ctx.getToken();
		
		UserResponse response = new UserResponse();
		String edata = request.getData();
		if(edata==null||"".equals(edata)) {
			response.setStatus(InitConst.API_STATUS_FAILED);
			response.setMessage("数据异常");
			log.info("user bindWechat response:{}", response);
			return response;
		}
		
		String data = null;
		try {
			data = EncrypUtil.desEncryptByToken(edata, token);
		} catch (Exception e) {
			response.setStatus(InitConst.API_STATUS_FAILED);
			response.setMessage("数据异常");
			log.info("user bindWechat response:{}", response);
			return response;
		}
		
		if(data!=null&&!"".equals(data)) {
			log.info("user bindWechat edata:{},", data);
			JSONObject info = JSONObject.parseObject(data);
			Object openid = info.getString("openid");
			Object nickName = info.getString("nickname");
			Object headimgurl = info.getString("headimgurl");
			if(openid==null||"".equals(openid.toString())) {
				response.setStatus(InitConst.API_STATUS_FAILED);
				response.setMessage("微信授权失败");
				log.info("user bindWechat response:{}", response);
				return response;
			}
			
			User user = this.userService.getByWechatOpenid(openid.toString());
			if(user!=null) {
				if(user.getPhone()!=null&&!"".equals(user.getPhone())) {
					if(!ctxUuid.equals(user.getUuid())) {
						response.setStatus(InitConst.API_STATUS_FAILED);
						response.setMessage("此微信号已绑定在其他账户下");
						log.info("user bindWechat response:{}", response);
						return response;
					}else {
						response.setStatus(InitConst.API_STATUS_FAILED);
						response.setMessage("此微信号已绑定在这个账户上");
						log.info("user bindWechat response:{}", response);
						return response;
					}
				}else {
					if(!ctxUuid.equals(user.getUuid())) {
						response.setStatus(InitConst.API_STATUS_FAILED);
						response.setMessage("此微信号已是注册用户，不能绑定");
						log.info("user bindWechat response:{}", response);
						return response;
					}else {
						response.setStatus(InitConst.API_STATUS_FAILED);
						response.setMessage("此微信号已绑定在这个账户上");
						log.info("user bindWechat response:{}", response);
						return response;
					}
				}
			}
			response = this.userService.bindWechat(
					ctxUuid, openid.toString(),nickName.toString(),headimgurl.toString());
		}
		log.info("user bindWechat response:{},", response);
		return response;
	}
	
}
*/